home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / mesa / mesa-glut / src-glut.aos / glutstuff.h < prev    next >
C/C++ Source or Header  |  2000-02-23  |  7KB  |  261 lines

  1. #if !defined(NDEBUG) && !defined(NODEBUG)
  2. #define    MESA_DEBUG
  3. #endif
  4.  
  5. /*
  6.  * Amiga GLUT graphics library toolkit
  7.  * Version:  1.1
  8.  * Copyright (C) 1998 Jarno van der Linden
  9.  *
  10.  * This library is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU Library General Public
  12.  * License as published by the Free Software Foundation; either
  13.  * version 2 of the License, or (at your option) any later version.
  14.  *
  15.  * This library is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18.  * Library General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU Library General Public
  21.  * License along with this library; if not, write to the Free
  22.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24.  
  25. /*
  26.  * glutstuff.h
  27.  *
  28.  * Version 1.0  27 Jun 1998
  29.  * by Jarno van der Linden
  30.  * jarno@kcbbs.gen.nz
  31.  *
  32.  * Version 1.1  02 Aug 1998
  33.  * by Jarno van der Linden
  34.  * jarno@kcbbs.gen.nz
  35.  *
  36.  * - Quantizer plugin support added
  37.  *
  38.  */
  39.  
  40. #include <exec/types.h>
  41. #include <intuition/intuition.h>
  42.  
  43. #include <GL/glut.h>
  44. #include <GL/amigamesa.h>
  45. #include <liblists.h>
  46.  
  47. #define    USE_CLIP_LAYER
  48.  
  49. /* public funtions of MesaGL */
  50. extern APTR glutPool;
  51.  
  52. APTR AllocVecPooled(register APTR poolHeader __asm__("a0"), register ULONG byteSize __asm__("d0"));
  53. void FreeVecPooled(register APTR poolHeader __asm__("a0"), register ULONG *memory __asm__("a1"));
  54.  
  55. /* Menus */
  56. #define IGNORE_IN_GAME_MODE(args...) \
  57.   { if (glutstuff.GameMode) return args; }
  58.  
  59. struct GlutMenuEntry {
  60.   struct nnode EntryNode;
  61. #define    EntryValue    EntryNode.data
  62.   struct GlutMenu *EntryMenu;
  63.  
  64.   const char *name;
  65.   BOOL issubmenu;
  66. };
  67.  
  68. struct GlutMenu {
  69.   struct nnode MenuNode;
  70. #define    MenuID        MenuNode.data
  71.   struct nlist MenuEntries;
  72. #define    NumEntries    MenuEntries.nodes
  73.  
  74.   void (*menufunc) (int value);
  75.  
  76.   BOOL needupdate;
  77. };
  78.  
  79. struct GlutTimer {
  80.   struct nnode TimerNode;
  81. #define    TimerValue    TimerNode.data
  82.  
  83.   ULONG secs, micros;
  84.   void (*timerfunc) (int value);
  85. };
  86.  
  87. struct GlutWindow {
  88.   struct nnode WindowNode;                    /* bind the windows together */
  89. #define    WinID        WindowNode.data
  90.   struct nlist SubWindows;                    /* bind all subwindows of this window together */
  91. #define    NumChildren    SubWindows.nodes
  92.   struct nnode SubWindowNode;                    /* a subwindow only have one parent, not more */
  93.   struct GlutWindow *SubWindowParent;                /* direct link backwards */
  94.   struct nlist WindowTimers;
  95.  
  96.   struct Window *window;
  97. #ifdef USE_CLIP_LAYER
  98.   struct Region *clipreg;
  99. #endif
  100.   amigaMesaContext context;
  101.  
  102.   APTR vi;
  103.  
  104.   struct Menu *menu;
  105.   struct GlutMenu *leftmenu, *middlemenu, *rightmenu;
  106.  
  107.   UWORD qualifiers;
  108.   int ignorekeyrepeat, repeatmode;
  109.   int mousex, mousey;
  110.   int joystickpoll, cursor;                        /* TODO */
  111.  
  112.   int winx, winy;                            /* Shape that we want */
  113.   int winwidth, winheight;
  114.   int wincurx, wincury;                            /* Shape that we believe it to currently be */
  115.   int wincurwidth, wincurheight;
  116.  
  117.   void (*displayfunc) (void);
  118.   void (*overlaydisplayfunc) (void);
  119.   void (*keyboardfunc) (unsigned char key, int x, int y);
  120.   void (*keyboardupfunc) (unsigned char key, int x, int y);        /* TODO */
  121.   void (*reshapefunc) (int width, int height);
  122.   void (*visibilityfunc) (int state);
  123.   void (*entryfunc) (int state);
  124.   void (*windowstatusfunc) (int status);                /* TODO */
  125.   void (*specialfunc) (int key, int x, int y);
  126.   void (*specialupfunc) (int key, int x, int y);            /* TODO */
  127.   void (*mousefunc) (int button, int state, int x, int y);
  128.   void (*joystickfunc) (unsigned int buttonMask, int x, int y, int z);    /* TODO */
  129.   void (*motionfunc) (int x, int y);
  130.   void (*passivemotionfunc) (int x, int y);
  131.  
  132.   BOOL needredisplay,
  133.     needreshape, needreshapegui,
  134.     needposition, needpositiongui,
  135.     needvisibility, visible,
  136.     needleftmenu, needmiddlemenu, needrightmenu,
  137.     fullscreen, lastoutwindow,
  138.     push, pop, show, hide, iconify;
  139. };
  140.  
  141. struct GlutGameMode {
  142.   struct MsgPort *backuped_port;
  143.   struct GlutWindow *backuped_window;
  144.   
  145.   struct Screen *GameScreen;
  146.   struct GlutWindow FakeyWindow;
  147. };
  148.  
  149. struct GlutStuff {
  150.   struct MsgPort *msgport;
  151.  
  152.   struct GlutWindow *activeWindow;                        /* window set by glutSetWindow() */
  153.   struct GlutWindow *curwin;
  154.   struct nlist Windows;
  155.   int nextwinid;
  156.  
  157.   struct GlutMenu *activeMenu;                            /* window set by glutSetMenu() */
  158.   struct GlutMenu *curmenu;
  159.   struct nlist Menues;
  160.   int nextmenuid;
  161.  
  162.   /* stuff for the glutInitWindow* functions */
  163.   int initposx, initposy,
  164.       initwidth, initheight,
  165.       scrwidth, scrheight;
  166.   unsigned int initdisplaymode;
  167.  
  168.   char *pubscreenname;
  169.  
  170.   /* basic overwriteable modes */
  171.   int doublemode,
  172.       rgbamode,
  173.       stereomode;
  174.   palMode palmode;
  175.  
  176.   GLboolean rgba,
  177.         alpha,
  178.         db,
  179.         accum,
  180.         depth,
  181.         stencil,
  182.         multisample,
  183.         stereo,
  184.         luminance;
  185.  
  186.   void (*idlefunc) (void);
  187.   void (*menustatefunc) (int state);
  188.   void (*menustatusfunc) (int status, int x, int y);
  189.  
  190.   ULONG basetime_secs, basetime_micros;
  191.   BOOL havebasetime;
  192.  
  193.   /* stuff for the glutGameModeString functions */
  194.   int gameposx, gameposy;
  195.   int gamewidth, gameheight;
  196.  
  197.   struct GlutGameMode *GameMode;
  198. };
  199.  
  200. /* deactive debugging-output only on request */
  201. #if !defined(NDEBUG) && !defined(NODEBUG)
  202. extern LONG debugOutputGLUT;
  203. #include <stdio.h>
  204. #define DEBUGOUT(level,str,args...) ({    \
  205.   if(debugOutputGLUT >= level) {    \
  206.  /* Printf(str,"gl  : "); */        \
  207.  /* Printf(str,##args);    */        \
  208.     fprintf(stderr,"glut: ");        \
  209.     fprintf(stderr,str,##args);        \
  210.     fflush(stderr);            \
  211.   }                    \
  212. })
  213. #else
  214. #define DEBUGOUT(level,str,args...) ({})
  215. #define    DEBUGOUT_REMOVED
  216. #endif
  217.  
  218. #define Error(str,args...) ({        \
  219. /*Printf("Fatal error: "); */        \
  220. /*Printf(str,##args); */        \
  221.   fprintf(stderr,"Fatal error: ");    \
  222.   fprintf(stderr,str,##args);        \
  223.   fflush(stderr);            \
  224.   abort();                \
  225. })
  226.  
  227. extern struct GlutStuff glutstuff;
  228. extern struct Library *IntuitionBase;
  229. extern struct Library *GfxBase;
  230. extern struct Library *DOSBase;
  231. extern struct Library *GadToolsBase;
  232. extern struct Library *LayersBase;
  233. extern struct ExecBase *SysBase;
  234.  
  235. int stuffGetNewWinID(void);
  236. struct GlutWindow *stuffGetWin(int winid);
  237. void stuffLinkInWin(struct GlutWindow *gw);
  238. void stuffLinkInSubWin(struct GlutWindow *gw, struct GlutWindow *gwn);
  239. void stuffLinkOutWin(struct GlutWindow *gw);
  240. void stuffMakeCurrent(struct GlutWindow *gw);
  241.  
  242. int stuffGetNewMenuID(void);
  243. struct GlutMenu *stuffGetMenu(int menuid);
  244. void stuffLinkInMenu(struct GlutMenu *gm);
  245. void stuffLinkOutMenu(struct GlutMenu *gm);
  246. void stuffMakeCurrentMenu(struct GlutMenu *gm);
  247.  
  248. struct GlutMenuEntry *stuffGetMenuEntry(int entry, struct GlutMenu *gm);
  249. void stuffLinkInMenuEntry(struct GlutMenuEntry *gme, struct GlutMenu *gm);
  250. void stuffLinkOutMenuEntry(struct GlutMenuEntry *gme, struct GlutMenu *gm);
  251.  
  252. #define    LayerWidth(l)        (l->bounds.MaxX - l->bounds.MinX + 1)
  253. #define    LayerHeight(l)        (l->bounds.MaxY - l->bounds.MinY + 1)
  254. #define    InnerWidth(w)        (w->Width - w->BorderLeft - w->BorderRight)
  255. #define    InnerHeight(w)        (w->Height - w->BorderTop - w->BorderBottom)
  256.  
  257. #ifdef USE_CLIP_LAYER
  258. struct Region *clipWindow(struct Window *win, LONG minX, LONG minY, LONG maxX, LONG maxY);
  259. struct Region *clipWindowToBorders(struct Window *win);
  260. #endif
  261.